package com.xiaoxin.nmzp.server.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.xiaoxin.nmzp.server.entity.domain.NmzpMessage;
import com.xiaoxin.nmzp.server.entity.req.MsgReq;
import com.xiaoxin.nmzp.server.entity.vo.MsgItemVO;
import com.xiaoxin.nmzp.server.service.NmzpMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nmzp/msg")
public class MsgController {
    @Autowired
    private NmzpMessageService nmzpMessageService;

    @PostMapping("/send")
    public AjaxResult sendMsg(@RequestBody MsgReq msgReq){
        nmzpMessageService.sendMsg(msgReq);
        return AjaxResult.success();
    }

    @GetMapping("/item")
    public AjaxResult getMsgItem(){
        List<MsgItemVO> msgItem = nmzpMessageService.selectMsgItem();
        return AjaxResult.success(msgItem);
    }

    @GetMapping("/{targetId}")
    public AjaxResult getMsg(@PathVariable("targetId") Long targetId){
        List<NmzpMessage> msgList = nmzpMessageService.getTargetMsg(targetId);
        return AjaxResult.success(msgList);
    }

}
